#!/bin/bash

# 设置UTF-8编码
export LANG=zh_CN.UTF-8
export LC_ALL=zh_CN.UTF-8

echo "🚀 数据库表结构导出工具 (Linux/Mac)"
echo "========================================"

# 检查Node.js是否安装
if ! command -v node &> /dev/null; then
    echo "❌ 错误: 未找到Node.js，请先安装Node.js"
    exit 1
fi

# 检查依赖是否安装
if [ ! -d "node_modules" ]; then
    echo "📦 正在安装依赖..."
    npm install mysql2
    if [ $? -ne 0 ]; then
        echo "❌ 依赖安装失败"
        exit 1
    fi
fi

echo "✅ 环境检查完成"
echo ""
echo "🔧 数据库连接配置:"
echo "   主机: ${DB_HOST:-43.143.253.188} (默认)"
echo "   端口: ${DB_PORT:-3306} (默认)"
echo "   用户: ${DB_USER:-nextjs} (默认)"
echo "   数据库: ${DB_NAME:-nextjs} (默认)"
echo ""
echo "💡 提示: 可以通过环境变量设置连接参数"
echo "    例如: export DB_HOST=your-host && export DB_PASSWORD=your-password"
echo ""

echo "🚀 开始导出数据库表结构..."
node export-database-schema.js

echo ""
echo "📁 导出完成! 请查看 schemas 目录"
